exports.handler = function(sid, query, callback) {
        
    var start = query.start + " 00:00:00";
    var end = query.end + " 00:00:00";
    var condition = {'time':{'$gte':start, '$lt':end}};
    if (query.openids) {
        condition['openid'] = {'$in':query.openids};
    }
    if (query.openid) {
        condition['openid'] = query.openid;
    }

    var db = gServers.getGameDB(sid);
    if (!db) {
       callback('db eror'); return;
    }

    var cursor = db.collection('pay').find(condition, {});
    cursor.each(function(err, item) {
        if (err || cursor.isClosed()) {
            callback(err); return;
        }
        
        var obj = [sid, item._id, item.openid, item.amt, item.cash, item.time];
        console.log(obj.join('\t')); 
    });
}

exports.checkQuery = function(query) {
    var start = query.start;
    var end = query.end;
    if (!start || !end || start.length != 10 || end.length != 10) {
        return false;
    }

    return true;
}

exports.help = function() {
    return [
        "start=yyyy-MM-dd end=yyyy-MM-dd [openids=file] [openid=xxx]",
        "导出充值订单订单,开始时间>=start,结束时间<end",
    ];
}

exports.getTitle = function(query) {
    var title = ['sid', '订单号', 'openid', '金额', '元宝', '时间'];
    console.log(title.join('\t'));
}
